package com.artwork.controller;

import com.artwork.common.domain.AjaxResult;
import com.artwork.common.enums.JsonResultEnum;
import com.artwork.common.exception.JsonException;
import com.artwork.model.Order;
import com.artwork.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author JoJo
 * @Data 2021/9/9$ 15:01$
 * @Description
 * @Param $
 * @Return $
 */
@RestController
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    /**
     * @desc 审核订单
     * @param id
     * @param status
     * @return
     * @throws JsonException
     */
    @PostMapping("/status")
    public AjaxResult pushOrder(int id, int status) throws JsonException{
        Order order = orderService.getOrderById(id);
        if (order == null){
            throw new JsonException(JsonResultEnum.ORDER_NULL);
        }
        orderService.pushOrder(id, status);
        return AjaxResult.success();
    }

    /**
     * @desc 删除订单
     * @param id
     * @return
     * @throws JsonException
     */
    @PostMapping("/delete")
    public AjaxResult deleteOrder(int id) throws JsonException {
        Order order = orderService.getOrderById(id);
        if (order == null){
            throw new JsonException(JsonResultEnum.ORDER_NULL);
        }
        orderService.deleteOrder(id);
        return AjaxResult.success();
    }
}
